package com.eascs.o2o.uc.dao.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import com.eascs.o2o.uc.dao.UserDao;
import com.eascs.o2o.uc.entity.UserEntity;

@Repository
public class UserDaoImpl extends UserDao {
	private final static int MEMBER_STATUS=0;
	
	public UserEntity queryUserEntity(UserEntity entity) {
		List<String> param=new ArrayList<>();
		StringBuffer sb=new StringBuffer();
		sb.append(" select * from fp_user f where f.status= " + MEMBER_STATUS);
		if (StringUtils.isNotBlank(entity.getAccount())) { 
			sb.append(" and f.account=? ");
			param.add(entity.getAccount());
		}
		if (StringUtils.isNotBlank(entity.getMobile())) {
			sb.append(" and f.mobile=? ");
			param.add(entity.getMobile());
		}
		if (StringUtils.isNotBlank(entity.getPassword())) {
			sb.append(" and f.password=? ");
			param.add(entity.getPassword());
		}
		return this.findEntity(sb.toString(), UserEntity.class, param.toArray());
	}

	public UserEntity insertUserEntity(UserEntity entity) {
		entity.setCreateTime(new Date());
		entity.setUpdateTime(new Date());
		boolean result = this.insert(entity);
		if (result) {
			return entity;
		}
		return null;
	}
}
